<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>附件上传</title>
<script type="text/javascript">
	var grid;
	$(function($) {
		grid = $("#grid").datagrid($.extend(datagridOption, {
			url : "${ctx}/basic/attachment/attachDataGrid",
			fitColumns : true,
			rownumbers : true,
			columns : [ [ {
				field : 'fileName',
				title : "文件名",
			}, {
				field : 'fileSize',
				title : "文件大小",
				formatter : function(val) {
					return val + "KB";
				},
				styler : function(value, row, index) {
					return 'text-align:right;';
				}
			}, {
				field : 'filePath',
				title : "文件路径",
			}, {
				field : 'fileType',
				title : "文件类型",
			}, {
				field : 'uploadTime',
				title : "上传时间",
			}, {
				field : 'lastDownloadTime',
				title : '最近下载时间',
			}, {
				field : 'operate',
				title : '操作',
				formatter : function(val, row) {
					return '<a class="easyui-linkbutton" iconCls="icon-hamburg-down" href="${ctx}/basic/attachment/download/' 
						+ row.id + '">下载</a>&nbsp;<a class="easyui-linkbutton" iconCls="icon-hamburg-busy" onclick="attach_del(\''
						+ row.fileName + '\',\'' + row.id + '\')">删除</a>';
				}
			} ] ]
		}));
		$("#search").click(function() {
			grid.datagrid('load', $("#tt").form("getData"));
		});
		$("#upload").click(function() {
			$("#dlg").dialog("open").dialog("setTitle", "文件上传");
		});
		$("#submit").click(function() {
			$("#fm").form("submit", {
				url : "${ctx}/basic/attachment/multiUpload",
				method : "post",
				success : function(data) {
					if (data.success) {
						grid.datagrid("reload", {});
						$("#dlg").dialog("close");
					}
					showMsg(data.msg);
				}
			});
		});
		$("#edit").click(function() {
			var rowData = grid.datagrid("getSelected");
			if (!rowData) {
				showInfo("您未选中行，无法编辑");
			} else {
				$("#dlg2").dialog("open").dialog("setTitle", "编辑附件信息");
				$("#fm2").form("clear").form("load", rowData);
			}
		});
		$("#fb").filebox({
			buttonText : "浏览...",
			buttonAlign: 'left'
		});
		$("#fb2").filebox({
			buttonText : "浏览...",
			buttonAlign: 'left'
		});
	});
	function attach_del(fileName, id) {
		showConfirm("确定删除附件\n[ " + fileName + " ]?", function() {
			$.post('${ctx}/basic/attachment/delete/' + id, function(result) {
				if (result.success) {
					grid.datagrid("reload");
				}
				showMsg(result.msg);
			}, 'json');
		});
	}
</script>
</head>
<body>
	<div data-options="region:'center',fit:true,border:false">
		<table id="grid">
		</table>
	</div>
	<div id="tt" class="easyui-toolbar">
		<span>文件名称：</span> <input type="text" name="search_LIKE_fileName"
			style="margin-left: 2px; margin-right: 2px; padding-left: 2px; padding-right: 3px;" />
		<a id="search" class="easyui-linkbutton"
			data-options="plain: true, iconCls: 'icon-hamburg-zoom'">查询</a> <a
			id="upload" class="easyui-linkbutton"
			data-options="plain: true, iconCls: 'icon-hamburg-contact'">上传</a> <a
			id="edit" class="easyui-linkbutton"
			data-options="plain: true, iconCls: 'icon-hamburg-pencil'">编辑</a>
	</div>
	<div id="dlg" class="easyui-dialog"
		style="width: 600px; height: 380px; padding: 10px 20px"
		data-options="iconCls:'icon-save',resizable:true,modal:true, buttons:[
                    { text: '提交', id: 'submit', iconCls: 'icon-ok'},
                    { text: '取消', iconCls:'icon-cancel', handler: function () { $('#dlg').dialog('close'); } }
                ],closed:true">
		<form id="fm" method="post" enctype="multipart/form-data">
			<table>
				<tr>
					<td>文件1:</td>
					<td><input class="easyui-filebox" id="fb" name="file1" style="width: 400px"></td>
				</tr>
				<tr>
					<td>文件2:</td>
					<td><input class="easyui-filebox" id="fb2" name="file2" style="width: 100%"></td>
				</tr>
			</table>
		</form>
	</div>
	<div id="dlg2" class="easyui-dialog"
		style="width: 600px; height: 380px; padding: 10px 20px"
		data-options="iconCls:'icon-save',resizable:true,modal:true, buttons:[
                    { text: '保存', iconCls: 'icon-ok', handler: function () { formSave('#fm2', '#grid', '#dlg2', '${ctx}/basic/attachment/update'); } },
                    { text: '取消', iconCls: 'icon-cancel', handler: function () { $('#dlg2').dialog('close'); } }
                ],closed:true">
		<form id="fm2" method="post" enctype="multipart/form-data">
			<input type="hidden" id="id" name="id">
			<table>
				<tr>
					<td>文件名:</td>
					<td><input class="easyui-validatebox" name="fileName" style="width: 400px"></td>
				</tr>
				<tr>
					<td>文件类型:</td>
					<td><input class="easyui-validatebox" name="fileType" style="width: 400px"></td>
				</tr>
			</table>
		</form>
	</div>
</body>
</html>